package com.wwtech.epp.ui.adapter.work;

import android.support.annotation.Nullable;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wwtech.epp.R;
import com.wwtech.epp.entity.TaskDetail;
import com.wwtech.epp.utils.WorkUtil;

import java.util.List;

/**
 * Created by hu on 2017/9/15.
 */

public class ProjectDetailProjectTaskAdapter extends BaseQuickAdapter<TaskDetail, BaseViewHolder> {

    public ProjectDetailProjectTaskAdapter(@Nullable List<TaskDetail> data) {
        super(R.layout.item_project_task, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, TaskDetail subJobBean) {
        baseViewHolder.setVisible(R.id.line, baseViewHolder.getLayoutPosition() == 0 ? false : true);
        baseViewHolder.setText(R.id.task_desc, subJobBean.getJobTitle());
        baseViewHolder.setText(R.id.task_part_and_time, subJobBean.getDeadline().substring(0, 10));     //subJobBean.getNickName() + " " +
        TextView state = baseViewHolder.getView(R.id.tv_task_status);
        if (WorkUtil.isUnValuableTask(subJobBean.getDeadline()) == -1 || subJobBean.getJobState() == 2) {
            switch (subJobBean.getJobState()) {
                case 0:
                    state.setText("新任务");
                    state.setTextColor(mContext.getResources().getColor(R.color.color_new_task));
                    state.setBackground(mContext.getResources().getDrawable(R.drawable.new_task_bg));
                    break;
                case 1:
                    state.setText("进行中");
                    state.setTextColor(mContext.getResources().getColor(R.color.main_color));
                    state.setBackground(mContext.getResources().getDrawable(R.drawable.ing_task_bg));
                    break;
                case 2:
                    state.setText("已完成");
                    state.setTextColor(mContext.getResources().getColor(R.color.color_finish_task));
                    state.setBackground(mContext.getResources().getDrawable(R.drawable.finish_task_bg));
                    break;
            }
        } else {
            state.setText("过期" + WorkUtil.isUnValuableTask(subJobBean.getDeadline()) + "天");
            state.setTextColor(mContext.getResources().getColor(R.color.color_f51818));
            state.setBackground(null);
        }
    }
}
